package com.openbravo.pos.inventory;

import com.openbravo.data.gui.MessageInf;
import com.openbravo.data.user.BrowsableEditableData;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.scanpal2.DeviceScanner;
import com.openbravo.pos.scanpal2.DeviceScannerException;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.ListModel;

public class JDlgUploadProducts extends JDialog
{
  private DeviceScanner m_scanner;
  private BrowsableEditableData m_bd;
  private JLabel jLabel1;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JButton jcmdCancel;
  private JButton jcmdOK;

  private JDlgUploadProducts(Frame paramFrame, boolean paramBoolean)
  {
    super(paramFrame, paramBoolean);
  }

  private JDlgUploadProducts(Dialog paramDialog, boolean paramBoolean)
  {
    super(paramDialog, paramBoolean);
  }

  private void init(DeviceScanner paramDeviceScanner, BrowsableEditableData paramBrowsableEditableData)
  {
    initComponents();
    getRootPane().setDefaultButton(this.jcmdOK);
    this.m_scanner = paramDeviceScanner;
    this.m_bd = paramBrowsableEditableData;
    setVisible(true);
  }

  private static Window getWindow(Component paramComponent)
  {
    if (paramComponent == null)
      return new JFrame();
    if (((paramComponent instanceof Frame)) || ((paramComponent instanceof Dialog)))
      return (Window)paramComponent;
    return getWindow(paramComponent.getParent());
  }

  public static void showMessage(Component paramComponent, DeviceScanner paramDeviceScanner, BrowsableEditableData paramBrowsableEditableData)
  {
    Window localWindow = getWindow(paramComponent);
    JDlgUploadProducts localJDlgUploadProducts;
    if ((localWindow instanceof Frame))
      localJDlgUploadProducts = new JDlgUploadProducts((Frame)localWindow, true);
    else
      localJDlgUploadProducts = new JDlgUploadProducts((Dialog)localWindow, true);
    localJDlgUploadProducts.init(paramDeviceScanner, paramBrowsableEditableData);
  }

  private void initComponents()
  {
    this.jPanel2 = new JPanel();
    this.jcmdOK = new JButton();
    this.jcmdCancel = new JButton();
    this.jPanel1 = new JPanel();
    this.jLabel1 = new JLabel();
    setDefaultCloseOperation(2);
    setTitle(AppLocal.getIntString("caption.upload"));
    setResizable(false);
    this.jPanel2.setLayout(new FlowLayout(2));
    this.jcmdOK.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png")));
    this.jcmdOK.setText(AppLocal.getIntString("Button.OK"));
    this.jcmdOK.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JDlgUploadProducts.this.jcmdOKActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdOK);
    this.jcmdCancel.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png")));
    this.jcmdCancel.setText(AppLocal.getIntString("Button.Cancel"));
    this.jcmdCancel.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JDlgUploadProducts.this.jcmdCancelActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.jcmdCancel);
    getContentPane().add(this.jPanel2, "South");
    this.jPanel1.setLayout(null);
    this.jLabel1.setText(AppLocal.getIntString("message.preparescanner"));
    this.jPanel1.add(this.jLabel1);
    this.jLabel1.setBounds(20, 30, 420, 15);
    getContentPane().add(this.jPanel1, "Center");
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((localDimension.width - 474) / 2, (localDimension.height - 161) / 2, 474, 161);
  }

  private void jcmdCancelActionPerformed(ActionEvent paramActionEvent)
  {
    dispose();
  }

  private void jcmdOKActionPerformed(ActionEvent paramActionEvent)
  {
    String str = this.jLabel1.getText();
    this.jLabel1.setText(AppLocal.getIntString("label.uploadingproducts"));
    this.jcmdOK.setEnabled(false);
    this.jcmdCancel.setEnabled(false);
    try
    {
      this.m_scanner.connectDevice();
      this.m_scanner.startUploadProduct();
      ListModel localListModel = this.m_bd.getListModel();
      for (int i = 0; i < localListModel.getSize(); i++)
      {
        Object[] arrayOfObject = (Object[])(Object[])localListModel.getElementAt(i);
        this.m_scanner.sendProduct((String)arrayOfObject[3], (String)arrayOfObject[2], (Double)arrayOfObject[6]);
      }
      this.m_scanner.stopUploadProduct();
      MessageInf   localMessageInf = new MessageInf(-83886080, AppLocal.getIntString("message.scannerok"));
      localMessageInf.show(this);
    }
    catch (DeviceScannerException localDeviceScannerException)
    {
      MessageInf localMessageInf = new MessageInf(-33554432, AppLocal.getIntString("message.scannerfail"), localDeviceScannerException);
      localMessageInf.show(this);
    }
    finally
    {
      this.m_scanner.disconnectDevice();
    }
    this.jLabel1.setText(str);
    this.jcmdOK.setEnabled(true);
    this.jcmdCancel.setEnabled(true);
    dispose();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.inventory.JDlgUploadProducts
 * JD-Core Version:    0.6.0
 */